﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace blackhouse.BlackApart.Business.Prices {
    public abstract class ApartmentPriceModifier {

        #region Properties

        public int ModificationFromVariable { get; set; }
        public int ModificationToVariable { get; set; }
        public int ModificationFixedVariable { get; set; }
        public PriceModificationType ModificationType { get; set; }
        public double ModificationChangeValue { get; set; }
        public double InitialPrice { get; set; }
        public DateTime ReservationFromDay { get; set; }
        public DateTime ReservationToDay { get; set; }
        public int ReservationNumberOfPeoples { get; set; }

        #endregion

        #region Methods

        public abstract void Prepare();

        public abstract double GetPriceForDay(DateTime priceForDay);

        public abstract double GetPriceDiffForDay(DateTime priceForDay);

        public abstract bool ModifierIsApplicable(DateTime priceForDay);

        protected double GetModifiedPrice(PriceModificationType modificationType, double modificationValue, double initialPrice) {
            switch (modificationType) {
                case PriceModificationType.Percent:
                    return Math.Floor(initialPrice + initialPrice * modificationValue / 100);
                case PriceModificationType.FixedValue:
                    return modificationValue;
                case PriceModificationType.Value:
                    return Math.Floor(initialPrice + modificationValue);
                default:
                    return initialPrice;
            }
        }

        public double GetPercentModification(DateTime priceForDay) {
            if (this.ModificationType == PriceModificationType.Percent && this.ModifierIsApplicable(priceForDay))
                return this.ModificationChangeValue;
            else return 0;
        }

        public double GetValueModification(DateTime priceForDay) {
            if (this.ModificationType == PriceModificationType.Value && this.ModifierIsApplicable(priceForDay))
                return this.ModificationChangeValue;
            else return 0;
        }

        public double GetNewValue(DateTime priceForDay) {
            if (this.ModificationType == PriceModificationType.FixedValue && this.ModifierIsApplicable(priceForDay))
                return this.ModificationChangeValue;
            else return 0;
        }

        #endregion

    }
}
